package com.yykj.backstage.all.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yykj.base.client.dto.BaseDepartmentDTO;
import com.yykj.common.vo.PageData;
import com.yykj.common.vo.ResultVO;
import com.yykj.hospital.client.dto.HospitalDTO;
import com.yykj.hospital.client.feign.HospitalServerFeignClient;
import com.yykj.hospital.client.form.HospitalEditForm;
import com.yykj.hospital.client.form.HospitalListForm;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api/backstage/all")
@Api(tags = "总后台相关接口")
@SuppressWarnings(value = "unchecked")
public class BackstageAllHospitalController {

    @PostMapping("/hospital/add")
    @ApiOperation("医院--添加")
    @ApiOperationSupport(ignoreParameters = {"id"})
    public ResultVO<HospitalDTO> addHospital(@RequestBody HospitalEditForm hospitalEditForm) {
        return ResultVO.success(hospitalServerFeignClient.createHospital(hospitalEditForm));
    }

    @PutMapping("/hospital/edit")
    @ApiOperation("医院--修改")
    public ResultVO<List<BaseDepartmentDTO>> editHospital(@RequestBody HospitalEditForm hospitalEditForm) {
        return ResultVO.success(hospitalServerFeignClient.editHospital(hospitalEditForm));
    }

    @DeleteMapping("/hospital/delete/{id}")
    @ApiOperation("医院--删除")
    public ResultVO deleteHospital(@PathVariable("id") Integer id) {
        hospitalServerFeignClient.deleteHospital(id);
        return ResultVO.success();
    }


    @GetMapping("/hospital/list")
    @ApiOperation(value = "医院列表")
    public ResultVO<PageData<HospitalDTO>> getHospitalList(
            @RequestParam(name = "currentPage",defaultValue = "1") Integer currentPage,
            @RequestParam(name = "pageSize",defaultValue = "10") Integer pageSize,
            @RequestParam(name = "name",required = false) String name  ) {

        return ResultVO.success(hospitalServerFeignClient.getHospitalList(currentPage,pageSize,name));
    }


    private HospitalServerFeignClient hospitalServerFeignClient;


    @Autowired
    public void setHospitalServerFeignClient(HospitalServerFeignClient hospitalServerFeignClient) {
        this.hospitalServerFeignClient = hospitalServerFeignClient;
    }
}
